package com.shm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.Campus;
import com.ruoyi.common.core.domain.vo.CampusVo;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.shm.service.ICampusService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 校区Controller
 *
 * @author dam
 * @date 2023-07-12
 */
@Api("校区管理")
@RestController
@RequestMapping("/market/campus")
public class CampusController extends BaseController {
    @Autowired
    private ICampusService campusService;

    /**
     * 查询校区列表
     */
    @PreAuthorize("@ss.hasPermi('market:campus:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Campus campus) {
        startPage();
        List<Campus> list = campusService.selectCampusList(campus);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('market:campus:list')")
    @PostMapping("/campusVoList")
    public TableDataInfo campusVoList(CampusVo campusVo) {
        List<CampusVo> list = campusService.selectCampusVoList(campusVo);
        TableDataInfo dataTable = getDataTable(list);
        return dataTable;
    }

    /**
     * 导出校区列表
     */
    @PreAuthorize("@ss.hasPermi('market:campus:export')")
    @Log(title = "校区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Campus campus) {
        List<Campus> list = campusService.selectCampusList(campus);
        ExcelUtil<Campus> util = new ExcelUtil<Campus>(Campus.class);
        util.exportExcel(response, list, "校区数据");
    }

    /**
     * 获取校区详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:campus:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(campusService.selectCampusById(id));
    }

    /**
     * 新增校区
     */
    @PreAuthorize("@ss.hasPermi('market:campus:add')")
    @Log(title = "校区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Campus campus) {
        return toAjax(campusService.insertCampus(campus));
    }

    /**
     * 修改校区
     */
    @PreAuthorize("@ss.hasPermi('market:campus:edit')")
    @Log(title = "校区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Campus campus) {
        return toAjax(campusService.updateCampus(campus));
    }

    /**
     * 删除校区
     */
    @PreAuthorize("@ss.hasPermi('market:campus:remove')")
    @Log(title = "校区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(campusService.deleteCampusByIds(ids));
    }
}
